package tgc.edu.exam.web.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.edu.exam.custom.DataGridParam;
import tgc.edu.exam.custom.DataGridUtils;
import tgc.edu.exam.custom.LayUiResult;
import tgc.edu.exam.entity.Teacherevaluation;
import tgc.edu.exam.service.TeacherevaluationService;
import tgc.edu.exam.web.form.TeacherevaluationForm;

@Controller
@RequestMapping(value="/teacherevaluation")
public class TeacherevaluationController {
	@Autowired
	private TeacherevaluationService teacherevaluationDAO;
	
	@RequestMapping(value="/manage")
	public void manage() {
		
	}
	
	@RequestMapping(value="/page")
	@ResponseBody
	public Object page(DataGridParam param, TeacherevaluationForm form) {
		Pageable pabeable = param.getPageable();
		Specification<Teacherevaluation> spec = buildSpec(form);
		Page<Teacherevaluation> page = teacherevaluationDAO.findAll(spec, pabeable);
		return DataGridUtils.buildResult(page);
	}

	private Specification<Teacherevaluation> buildSpec(TeacherevaluationForm form) {
		return null;
	}
	
	@RequestMapping(value="/edit")
	public void edit(String id, ModelMap map) {
		Teacherevaluation model=new Teacherevaluation();
		if(id!=null) {
			model=teacherevaluationDAO.findById(UUID.fromString(id));
		}
		map.put("model", model);
	}
	
	@RequestMapping(value="/delete")
	@ResponseBody
	public Object delete(String id) {
		teacherevaluationDAO.deleteById(UUID.fromString(id));
		return LayUiResult.getResult("删除成功");
	}
}
